package com.flyou.ccnucenter;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.flyou.ccnucenter.service.WidgetService;

public class AppWidget extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        // There may be multiple widgets active, so update all of them
        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }


    @Override
    public void onEnabled(Context context) {
     context.startService(new Intent(context, WidgetService.class));
    }

    @Override
    public void onDisabled(Context context) {
        context.stopService(new Intent(context, WidgetService.class));
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        LayoutInflater layoutInflater=LayoutInflater.from(context);
        View view = layoutInflater.inflate(R.layout.widget, null);
        switch (intent.getAction())
        {
            case "ball":
                Toast.makeText(context, "ball", Toast.LENGTH_SHORT).show();

                view.findViewById(R.id.ball).setVisibility(View.VISIBLE);
                view.findViewById(R.id.book).setVisibility(View.GONE);
                view.findViewById(R.id.calendar).setVisibility(View.GONE);

                break;
            case "book":
                Toast.makeText(context, "book", Toast.LENGTH_SHORT).show();
                view.findViewById(R.id.book).setVisibility(View.VISIBLE);
                view.findViewById(R.id.ball).setVisibility(View.GONE);
                view.findViewById(R.id.calendar).setVisibility(View.GONE);
                break;
            case "calendar":
                Toast.makeText(context, "calendar", Toast.LENGTH_SHORT).show();
                view.findViewById(R.id.calendar).setVisibility(View.VISIBLE);
                view.findViewById(R.id.ball).setVisibility(View.GONE);
                view.findViewById(R.id.book).setVisibility(View.GONE);
                break;

        }
        super.onReceive(context, intent);
    }
}

